package xyz.xuminghai.javafx_learn.scene.control;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

/**
 * 2023/1/16 14:35 星期一<br/>
 *
 * @author xuMingHai
 */
public class ButtonApp extends Application {

    private final AnchorPane anchorPane = new AnchorPane();

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void init() {
        Button button = new Button("Button");

        // 默认是ActionEvent
//		button.fire();

        // 执行优先级
        button.setOnAction(System.out::println);

        button.addEventFilter(MouseEvent.MOUSE_CLICKED, event -> System.out.println("EventFilter"));

        button.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> System.out.println("EventHandler"));

        button.setStyle("""
                -fx-border-color: aquamarine;
                -fx-border-insets: 2px;
                -fx-border-radius: 5%;
                -fx-border-width: 3;
                -fx-border-style: DASHED;
                -fx-background-color: antiquewhite;
                -fx-font-size: 12px;
                """);

        anchorPane.getChildren().add(button);
        AnchorPane.setTopAnchor(button, 100.0);
        AnchorPane.setLeftAnchor(button, 100.0);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        primaryStage.setScene(new Scene(anchorPane, 800, 600));
        primaryStage.show();
    }
}
